package demo;

import java.util.Scanner;

public class ThreadDemo1 {
    volatile static int flag = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            while (flag==0) {

            }
        });

        Thread t2 = new Thread(()->{
            Scanner scanner = new Scanner(System.in);
            flag = scanner.nextInt();//用户输入非零的数后程序本应结束
        });

        t1.start();
        t2.start();
    }
}
